from django.db import models
import PIL

# Create your models here.
class Seller(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=32)
    nickname = models.CharField(max_length=32)
    password = models.CharField(max_length=32)

class Type(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=32)

class Goods(models.Model):
    goods_num = models.CharField(max_length=32)
    goods_name = models.CharField(max_length=32)
    goods_oprice = models.IntegerField()
    goods_cprice = models.IntegerField()
    goods_kucun = models.IntegerField()
    goods_description = models.CharField(max_length=32)
    goods_details = models.TextField()
    goods_sales = models.IntegerField()
    goods_browses = models.IntegerField(default=0)
    types = models.ForeignKey(to='Type', on_delete=models.CASCADE)
    seller = models.ForeignKey(to='Seller', on_delete=models.CASCADE)

    def __str__(self):
        return "<Goods object:{}-{}-{}-{}-{}-{}-{}-{}-{}-{}".format(
            self.pk, self.goods_num, self.goods_name, self.goods_oprice,
            self.goods_cprice, self.goods_kucun, self.goods_description,
            self.goods_details, self.goods_sales, self.goods_browses
        )

class Image(models.Model):
    img_address = models.ImageField()
    img_label = models.CharField(max_length=32)
    goods = models.ForeignKey(to='Goods', on_delete=models.CASCADE)
